package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;
import com.chinanet.utils.pon.ZXGetFinalResult;
import com.chinanet.utils.pon.ZX_SocketClient;

import java.util.HashMap;
import java.util.Map;
/**
 * ZX_Query_OLT_CRC_Imp
 * 中兴PON网管-OLT上行CRC误码率查询
 * @author xuzhi
 *
 */
public class ZX_Query_OLT_CRC_Imp implements WorkInterFace {

	public String getName() {
		return "中兴PON网管-OLT上行CRC误码率查询";
	}

	public String getDesciption() {
		return "";
	}

	public int getVersion() {
		return 0;
	}

	public Attr[] getInAttrs() {
		Attr[] in = new Attr[2];
//		in[0] = new Attr("Port", "端口号", AttrType.TYPE_String, true);
		in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
		in[1] =	new Attr("PORTID", "LAN端口ID，通过“机架-框-槽号-端口”的方式定位，没有的补为“NA”", AttrType.TYPE_String, true);
		return in;
	}

	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[3];
		out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
		out[1] = new Attr("CRC", "CRC误码率", AttrType.TYPE_String, true);
		out[2] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	public Map<String, Object> init(Map<String, Object> data) {
		Map<String, Object> inmap = new HashMap<String, Object>();
		Map<String, Object> outmap = new HashMap<String, Object>();
		ZXGetFinalResult result = new ZXGetFinalResult();
		String ip ="134.103.235.44";
		int port = 9820;
		ZX_SocketClient hclient = new ZX_SocketClient(ip, port);
		HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
		attrsin.setOLTID((String) data.get("OLTID"));
		attrsin.setPORTID((String)data.get("PORTID"));
		inmap = hclient.init(attrsin,
				OperationType.TYPE_Query_OLT_CRC);

		boolean flag = (Boolean) inmap.get("flag");
		if (flag) {
			outmap.put("flag", 1);
			String CRC = "";
			try {
				CRC = result.returnOltCRC((String) inmap.get("ownlog"),1);
			} catch (Exception e) {
				CRC = "读取出错";
			}

			outmap.put("CRC", CRC);
			outmap.put("log", inmap.get("log"));
		} else {
			outmap.put("flag", 0);
			outmap.put("CRC", "");
			outmap.put("log", inmap.get("log"));

		}


		return outmap;
	}

}
